﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rotempco.BaseClass.Objects.ReturnObjects;
using Rotempco.BaseClass;
using Rotempco.BaseClass.Objects.Enums;
using Rotempco.Website.Objects;
using Rotempco.Core.ORM.Objects.Stores;
using Rotempco.Core.Logic;

namespace Rotempco.Website.WebPages.Admin.Login
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_SendClick(object sender, EventArgs e)
        {
            LoginResult loginResult = Factory.LoginUser.Login(textbox_Email.Text, textBox_Password.Text);

            switch (loginResult.LoginResultEnum)
            {
                case LoginResultEnum.Success:
                    SessionStore.Instance.PrivateEncryptionKey = CoreSettingsLogic.GetPrivateDecryptionKey();
                    Response.Redirect("/Admin/");
                    break;
                case LoginResultEnum.AccountSuspended:
                    TimeSpan timeSpan = loginResult.AccountSuspendedUntil.Value - DateTime.Now;
                    label_ErrorMessage.Text = "Account suspended for " + Math.Round(timeSpan.TotalMinutes) + " minutes";
                    break;
                case LoginResultEnum.ChangePassword:
                    SessionStore.Instance.PrivateEncryptionKey = CoreSettingsLogic.GetPrivateDecryptionKey();
                    Response.Redirect("/Admin/ChangePassword/Default.aspx");
                    break;
                case LoginResultEnum.InvalidEmail:
                case LoginResultEnum.InvalidPassword:
                case LoginResultEnum.LoginUserNotFound:
                default:
                    label_ErrorMessage.Text = "Wrong username or password";
                    break;
            }
        }

        protected void Button_ForgotpasswordClick(object sender, EventArgs e)
        {
            //TODO: Implement forgot password logic.
            throw new NotImplementedException();
        }
    }
}